//
//  AddLadingBillCell.m
//  ReceiptDelivery
//
//  Created by 吕晶 on 2020/7/2.
//  Copyright © 2020 吕晶. All rights reserved.
//

#import "AddLadingBillCell.h"
#import "AddLadingBillModel.h"

@interface AddLadingBillCell ()

@property (nonatomic, strong) UITextField *supplierField;
@property (nonatomic, strong) UIButton *supplierBtn;
@property (nonatomic, strong) UITextField *heTongField;
@property (nonatomic, strong) UIButton *heTongBtn;
@property (nonatomic, strong) UIView *bgView;
@property (nonatomic, strong) UIImageView *tiImgView;
@property (nonatomic, strong) UILabel *tiNameLab;
@property (nonatomic, strong) UILabel *tiAddressLab;
@property (nonatomic, strong) UILabel *tiCompanyLab;
@property (nonatomic, strong) UILabel *desc1Lab;
@property (nonatomic, strong) UILabel *marginLine;
@property (nonatomic, strong) UIImageView *shouImgView;
@property (nonatomic, strong) UILabel *shouNameLab;
@property (nonatomic, strong) UILabel *shouAddressLab;
@property (nonatomic, strong) UILabel *shouCompanyLab;
@property (nonatomic, strong) UILabel *desc2Lab;
@property (nonatomic, strong) UILabel *marginLine2;
@property (nonatomic, strong) UILabel *linkLine;

@property (nonatomic, strong) UILabel *tiLine;
@property (nonatomic, strong) UIImageView *tiAddressImgView;
@property (nonatomic, strong) UILabel *tiDescLab;
@property (nonatomic, strong) UIButton *tiBtn;
@property (nonatomic, strong) UILabel *shouLine;
@property (nonatomic, strong) UIImageView *shouAddressImgView;
@property (nonatomic, strong) UILabel *shouDescLab;
@property (nonatomic, strong) UIButton *shouBtn;

@property (nonatomic, strong) UILabel *timeXingLab;
@property (nonatomic, strong) UILabel *timetitleLab;
@property (nonatomic, strong) UITextField *beginField;
@property (nonatomic, strong) UIButton *beginBtn;
@property (nonatomic, strong) UILabel *timeLine;
@property (nonatomic, strong) UITextField *endField;
@property (nonatomic, strong) UIButton *endBtn;
@property (nonatomic, strong) UILabel *marginLine3;

@property (nonatomic, strong) UITextField *dateField;
@property (nonatomic, strong) UIButton *dateBtn;
@property (nonatomic, strong) UILabel *marginLine4;
@property (nonatomic, strong) UITextField *linkOrderField;//关联订单
@property (nonatomic, strong) UILabel *marginLine5;
@property (nonatomic, strong) UITextField *originalOrderField;//原始单号

@end

@implementation AddLadingBillCell

+ (instancetype)AddLadingBillCellWithTableView:(UITableView *)tableView {
    static NSString *cellID = @"AddLadingBillCell";
    AddLadingBillCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[AddLadingBillCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = Color_backgroundColor;
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        self.supplierField = [UITextField new];
        self.supplierField.font = [UIFont systemFontOfSize:14];
        self.supplierField.textColor = HexColor(0x2B2C44);
        self.supplierField.backgroundColor = HexColor(0xffffff);
//        self.supplierField.layer.masksToBounds = YES;
//        self.supplierField.layer.cornerRadius = 6;
        self.supplierField.placeholder = @"请选择";
        self.supplierField.textAlignment = NSTextAlignmentRight;
        [self.contentView addSubview:self.supplierField];
        
        
        self.supplierBtn = [UIButton new];
        [self.supplierBtn addTarget:self action:@selector(supplierClick) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:self.supplierBtn];
        
        self.heTongField = [UITextField new];
        self.heTongField.font = [UIFont systemFontOfSize:14];
        self.heTongField.textColor = HexColor(0x2B2C44);
        self.heTongField.backgroundColor = HexColor(0xffffff);
//        self.heTongField.layer.masksToBounds = YES;
//        self.heTongField.layer.cornerRadius = 6;
        self.heTongField.placeholder = @"请选择";
        self.heTongField.textAlignment = NSTextAlignmentRight;
        [self.contentView addSubview:self.heTongField];
        
        
        self.heTongBtn = [UIButton new];
        [self.heTongBtn addTarget:self action:@selector(heTongClick) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:self.heTongBtn];
        
        self.bgView = [UIView new];
        self.bgView.backgroundColor = HexColor(0xffffff);
        self.bgView.layer.masksToBounds = YES;
        self.bgView.layer.cornerRadius = 6;
        [self.contentView addSubview:self.bgView];
        
        self.tiImgView = [UIImageView new];
        self.tiImgView.image = [UIImage imageNamed:@"icon_add_ti"];
        [self.bgView addSubview:self.tiImgView];
        
        self.tiNameLab = [UILabel new];
        self.tiNameLab.textColor = HexColor(0x2B2C44);
        self.tiNameLab.font = BoldFontOfSize(16);
        [self.bgView addSubview:self.tiNameLab];
        
        self.tiAddressLab = [UILabel new];
        self.tiAddressLab.textColor = HexColor(0x2B2C44);
        self.tiAddressLab.font = [UIFont systemFontOfSize:14];
        self.tiAddressLab.numberOfLines = 0;
        [self.bgView addSubview:self.tiAddressLab];
        
        self.tiCompanyLab = [UILabel new];
        self.tiCompanyLab.textColor = HexColor(0x2B2C44);
        self.tiCompanyLab.font = [UIFont systemFontOfSize:14];
        self.tiCompanyLab.numberOfLines = 0;
        [self.bgView addSubview:self.tiCompanyLab];
        
        self.desc1Lab = [UILabel new];
        self.desc1Lab.textColor = HexColor(0xDBDCE6);
        self.desc1Lab.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:self.desc1Lab];
        
        self.marginLine = [UILabel new];
        self.marginLine.backgroundColor = HexColor(0xF2F2F5);
        [self.bgView addSubview:self.marginLine];
        
        self.shouImgView = [UIImageView new];
        self.shouImgView.image = [UIImage imageNamed:@"icon_add_shou"];
        [self.bgView addSubview:self.shouImgView];
        
        self.shouNameLab = [UILabel new];
        self.shouNameLab.textColor = HexColor(0x2B2C44);
        self.shouNameLab.font = BoldFontOfSize(16);
        [self.bgView addSubview:self.shouNameLab];
        
        self.shouAddressLab = [UILabel new];
        self.shouAddressLab.textColor = HexColor(0x2B2C44);
        self.shouAddressLab.font = [UIFont systemFontOfSize:14];
        self.shouAddressLab.numberOfLines = 0;
        [self.bgView addSubview:self.shouAddressLab];
        
        self.shouCompanyLab = [UILabel new];
        self.shouCompanyLab.textColor = HexColor(0x2B2C44);
        self.shouCompanyLab.font = [UIFont systemFontOfSize:14];
        self.shouCompanyLab.numberOfLines = 0;
        [self.bgView addSubview:self.shouCompanyLab];
        
        self.desc2Lab = [UILabel new];
        self.desc2Lab.textColor = HexColor(0xDBDCE6);
        self.desc2Lab.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:self.desc2Lab];
        
        self.marginLine2 = [UILabel new];
        self.marginLine2.backgroundColor = HexColor(0xF2F2F5);
        [self.bgView addSubview:self.marginLine2];
        
        self.linkLine = [UILabel new];
        self.linkLine.backgroundColor = HexColorA(0x3D68EB, 0.2);
        [self.bgView addSubview:self.linkLine];
        
        self.tiLine = [UILabel new];
        self.tiLine.backgroundColor = HexColor(0xF2F2F5);
        [self.bgView addSubview:self.tiLine];
        
        self.tiAddressImgView = [UIImageView new];
        self.tiAddressImgView.image = [UIImage imageNamed:@"icon_choose_address"];
        [self.bgView addSubview:self.tiAddressImgView];
        
        self.tiDescLab = [UILabel new];
        self.tiDescLab.textColor = HexColor(0x585974);
        self.tiDescLab.font = [UIFont systemFontOfSize:10];
        [self.bgView addSubview:self.tiDescLab];
        
        self.tiBtn = [UIButton new];
        [self.tiBtn addTarget:self action:@selector(tiClick) forControlEvents:UIControlEventTouchUpInside];
        [self.bgView addSubview:self.tiBtn];
        
        self.shouLine = [UILabel new];
        self.shouLine.backgroundColor = HexColor(0xF2F2F5);
        [self.bgView addSubview:self.shouLine];
        
        self.shouAddressImgView = [UIImageView new];
        self.shouAddressImgView.image = [UIImage imageNamed:@"icon_choose_address"];
        [self.bgView addSubview:self.shouAddressImgView];
        
        self.shouDescLab = [UILabel new];
        self.shouDescLab.textColor = HexColor(0x585974);
        self.shouDescLab.font = [UIFont systemFontOfSize:10];
        [self.bgView addSubview:self.shouDescLab];
        
        self.shouBtn = [UIButton new];
        [self.shouBtn addTarget:self action:@selector(shouClick) forControlEvents:UIControlEventTouchUpInside];
        [self.bgView addSubview:self.shouBtn];
        
        self.timeXingLab = [UILabel new];
        self.timeXingLab.textColor = HexColor(0xF35959);
        self.timeXingLab.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:self.timeXingLab];
        
        self.timetitleLab = [UILabel new];
        self.timetitleLab.textColor = HexColor(0x2B2C44);
        self.timetitleLab.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:self.timetitleLab];
        
        self.beginField = [UITextField new];
        self.beginField.placeholder = @"开始提货时间";
        self.beginField.textColor = HexColor(0x2B2C44);
        self.beginField.font = [UIFont systemFontOfSize:14];
        self.beginField.textAlignment = NSTextAlignmentCenter;
        [self.bgView addSubview:self.beginField];
        
        self.beginBtn = [UIButton new];
        [self.beginBtn addTarget:self action:@selector(beginClick) forControlEvents:UIControlEventTouchUpInside];
        [self.bgView addSubview:self.beginBtn];
        
        self.timeLine = [UILabel new];
        self.timeLine.textColor = HexColor(0xBDBED9);
        self.timeLine.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:self.timeLine];
        
        self.endField = [UITextField new];
        self.endField.placeholder = @"截止提货时间";
        self.endField.textColor = HexColor(0x2B2C44);
        self.endField.font = [UIFont systemFontOfSize:14];
        self.endField.textAlignment = NSTextAlignmentCenter;
        [self.bgView addSubview:self.endField];
        
        self.endBtn = [UIButton new];
        [self.endBtn addTarget:self action:@selector(endClick) forControlEvents:UIControlEventTouchUpInside];
        [self.bgView addSubview:self.endBtn];
        
        self.marginLine3 = [UILabel new];
        self.marginLine3.backgroundColor = HexColor(0xF2F2F5);
        [self.bgView addSubview:self.marginLine3];
        
        self.dateField = [UITextField new];
        self.dateField.font = [UIFont systemFontOfSize:14];
        self.dateField.textColor = HexColor(0x2B2C44);
        self.dateField.placeholder = @"请选择日期";
        self.dateField.textAlignment = NSTextAlignmentRight;
        [self.bgView addSubview:self.dateField];
        
        self.dateBtn = [UIButton new];
        [self.dateBtn addTarget:self action:@selector(dateClick) forControlEvents:UIControlEventTouchUpInside];
        [self.bgView addSubview:self.dateBtn];
        
        self.marginLine4 = [UILabel new];
        self.marginLine4.backgroundColor = HexColor(0xF2F2F5);
        [self.bgView addSubview:self.marginLine4];
        
        self.linkOrderField = [UITextField new];
        self.linkOrderField.font = [UIFont systemFontOfSize:14];
        self.linkOrderField.textColor = HexColor(0x2B2C44);
        self.linkOrderField.placeholder = @"请输入";
        self.linkOrderField.textAlignment = NSTextAlignmentRight;
        [self.linkOrderField addTarget:self action:@selector(linkFieldTextChanged:) forControlEvents:UIControlEventEditingChanged];
        [self.bgView addSubview:self.linkOrderField];
        
        self.marginLine5 = [UILabel new];
        self.marginLine5.backgroundColor = HexColor(0xF2F2F5);
        [self.bgView addSubview:self.marginLine5];
        
        self.originalOrderField = [UITextField new];
        self.originalOrderField.font = [UIFont systemFontOfSize:14];
        self.originalOrderField.textColor = HexColor(0x2B2C44);
        self.originalOrderField.placeholder = @"请输入";
        self.originalOrderField.textAlignment = NSTextAlignmentRight;
        [self.originalOrderField addTarget:self action:@selector(oriFieldTextChanged:) forControlEvents:UIControlEventEditingChanged];
        [self.bgView addSubview:self.originalOrderField];
    }
    return self;
}

- (void)linkFieldTextChanged:(UITextField *)field {
    if (self.linkOrderBlock) {
        self.linkOrderBlock(field.text);
    }
}

- (void)oriFieldTextChanged:(UITextField *)field {
    if (self.oriOrderBlock) {
        self.oriOrderBlock(field.text);
    }
}

-(void)setModel:(AddLadingBillModel *)model {
    _model = model;
    [self configUI];
}

- (void)supplierClick {
    if (self.supplierBlock) {
        self.supplierBlock();
    }
}

- (void)beginClick {
    if (self.beginBlock) {
        self.beginBlock();
    }
}

- (void)endClick {
    if (self.endBlock) {
        self.endBlock();
    }
}

- (void)dateClick {
    if (self.dateBlock) {
        self.dateBlock();
    }
}

- (void)heTongClick {
    if (self.heTongBlock) {
        self.heTongBlock();
    }
}

- (void)tiClick {
    if (self.tiAddressBlock) {
        self.tiAddressBlock();
    }
}

- (void)shouClick {
    if (self.shouAddressBlock) {
        self.shouAddressBlock();
    }
}

- (void)configUI {
    self.supplierField.frame = CGRectMake(15, 15, ScreenW - 30, 56);
    [self.supplierField setBorderWithCornerRadius:6 borderWidth:0 borderColor:[UIColor clearColor] type:UIRectCornerTopLeft | UIRectCornerTopRight];
    self.supplierBtn.frame = self.supplierField.frame;
    
    UIView *sleftView = [[UIView alloc] initWithFrame:CGRectMake(0, 20, 100, 15)];
    UILabel *sxingLab = [UILabel new];
    sxingLab.text = @"*";
    sxingLab.font = [UIFont systemFontOfSize:14];
    sxingLab.textColor = HexColor(0xF35959);
    [sxingLab sizeToFit];
    sxingLab.nim_left = 10;
    sxingLab.nim_top = 0;
    [sleftView addSubview:sxingLab];
    
    UILabel *stitleLab = [[UILabel alloc] initWithFrame:CGRectMake(sxingLab.nim_right + 3, 0, sleftView.nim_width - sxingLab.nim_right - 3, sleftView.nim_height)];
    stitleLab.text = @"选择供应商";
    stitleLab.textColor = HexColor(0x2B2C44);
    stitleLab.font = [UIFont systemFontOfSize:14];
    [sleftView addSubview:stitleLab];
    
    self.supplierField.leftView = sleftView;
    self.supplierField.leftViewMode = UITextFieldViewModeAlways;
    UIView *srightView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 38, 18)];
    UIImageView *sarrowImgView = [[UIImageView alloc] initWithFrame:CGRectMake(5, 0, 18, 18)];
    sarrowImgView.image = [UIImage imageNamed:@"icon_right_arrow"];
    [srightView addSubview:sarrowImgView];
    
    self.supplierField.rightView = srightView;
    self.supplierField.rightViewMode = UITextFieldViewModeAlways;
    
    if (self.model.supplier.name.length) {
        self.supplierField.text = self.model.supplier.name;
    }
    
    self.heTongField.frame = CGRectMake(15, self.supplierBtn.nim_bottom, ScreenW - 30, 56);
    [self.heTongField setBorderWithCornerRadius:6 borderWidth:0 borderColor:[UIColor clearColor] type:UIRectCornerBottomLeft | UIRectCornerBottomRight];
    if (self.model.heTong.constract_sn.length) {
        self.heTongField.text = [NSString stringWithFormat:@"%@/%@",self.model.heTong.constract_sn,self.model.heTong.name];
    }
    self.heTongBtn.frame = self.heTongField.frame;
    UIView *leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 20, 100, 15)];
    UILabel *xingLab = [UILabel new];
    xingLab.text = @"*";
    xingLab.font = [UIFont systemFontOfSize:14];
    xingLab.textColor = HexColor(0xF35959);
    [xingLab sizeToFit];
    xingLab.nim_left = 10;
    xingLab.nim_top = 0;
    [leftView addSubview:xingLab];
    
    UILabel *titleLab = [[UILabel alloc] initWithFrame:CGRectMake(xingLab.nim_right + 3, 0, leftView.nim_width - xingLab.nim_right - 3, leftView.nim_height)];
    titleLab.text = @"选择合同";
    titleLab.textColor = HexColor(0x2B2C44);
    titleLab.font = [UIFont systemFontOfSize:14];
    [leftView addSubview:titleLab];
    
    self.heTongField.leftView = leftView;
    self.heTongField.leftViewMode = UITextFieldViewModeAlways;
    
    UIView *rightView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 38, 18)];
    UIImageView *arrowImgView = [[UIImageView alloc] initWithFrame:CGRectMake(5, 0, 18, 18)];
    arrowImgView.image = [UIImage imageNamed:@"icon_right_arrow"];
    [rightView addSubview:arrowImgView];
    
    self.heTongField.rightView = rightView;
    self.heTongField.rightViewMode = UITextFieldViewModeAlways;
    
    self.bgView.nim_left = self.heTongField.nim_left;
    self.bgView.nim_top = self.heTongField.nim_bottom + 10;
    self.bgView.nim_width = ScreenW - 2 * self.bgView.nim_left;
    
    if (self.model.tiAddress.liaison.length) {
        self.desc1Lab.frame = CGRectZero;
        
        self.tiNameLab.text = [NSString stringWithFormat:@"%@ %@",self.model.tiAddress.liaison,self.model.tiAddress.tel];
        [self.tiNameLab sizeToFit];
        self.tiNameLab.nim_left = 59;
        self.tiNameLab.nim_top = 15;
        self.tiNameLab.nim_width = self.bgView.nim_width - 70 - 10 - self.tiNameLab.nim_left;
        
        self.tiAddressLab.nim_width = self.tiNameLab.nim_width;
        self.tiAddressLab.text = self.model.tiAddress.address;
        self.tiAddressLab.nim_left = self.tiNameLab.nim_left;
        self.tiAddressLab.nim_top = self.tiNameLab.nim_bottom + 10;
        [self.tiAddressLab sizeToFit];
        self.tiAddressLab.nim_width = self.tiNameLab.nim_width;
        
        self.tiCompanyLab.nim_width = self.tiAddressLab.nim_width;
        self.tiCompanyLab.text = self.model.tiAddress.name;
        self.tiCompanyLab.nim_left = self.tiAddressLab.nim_left;
        self.tiCompanyLab.nim_top = self.tiAddressLab.nim_bottom + 5;
        [self.tiCompanyLab sizeToFit];
        self.tiCompanyLab.nim_width = self.tiAddressLab.nim_width;
        
        
        self.marginLine.nim_left = self.tiNameLab.nim_left - 5;
        self.marginLine.nim_top = self.tiCompanyLab.nim_bottom + 10;
        self.marginLine.nim_width = self.bgView.nim_width - self.marginLine.nim_left;
        self.marginLine.nim_height = 1;
        
    }else {
        self.desc1Lab.frame = CGRectMake(59, 39, self.bgView.nim_width - 70 - 10 - 59, 15);
        self.desc1Lab.text = @"提货信息";
        self.tiNameLab.frame = CGRectZero;
        self.tiAddressLab.frame = CGRectZero;
        self.tiCompanyLab.frame = CGRectZero;
        
        self.marginLine.nim_left = self.desc1Lab.nim_left - 5;
        self.marginLine.nim_top = self.desc1Lab.nim_bottom + 33;
        self.marginLine.nim_width = self.bgView.nim_width - self.marginLine.nim_left;
        self.marginLine.nim_height = 1;
    }
    
    self.tiImgView.nim_width = 22;
    self.tiImgView.nim_height = 22;
    self.tiImgView.nim_left = 20;
    self.tiImgView.nim_top = (self.marginLine.nim_top - self.tiImgView.nim_width) * 0.5;
    
    self.tiLine.nim_width = 1;
    self.tiLine.nim_height = 40;
    self.tiLine.nim_left = self.bgView.nim_width - 70 - self.tiLine.nim_width;
    self.tiLine.nim_centerY = self.tiImgView.nim_centerY;
    
    self.tiAddressImgView.nim_width = 18;
    self.tiAddressImgView.nim_height = 18;
    self.tiAddressImgView.nim_top = self.tiLine.nim_top + 2;
    self.tiAddressImgView.nim_left = self.tiLine.nim_right + (70 - self.tiAddressImgView.nim_width) * 0.5;
    
    self.tiDescLab.text = @"提货地址";
    [self.tiDescLab sizeToFit];
    self.tiDescLab.nim_top = self.tiAddressImgView.nim_bottom + 6;
    self.tiDescLab.nim_centerX = self.tiAddressImgView.nim_centerX;
    
    self.tiBtn.nim_left = self.tiLine.nim_right;
    self.tiBtn.nim_top = self.tiLine.nim_top;
    self.tiBtn.nim_width = 70;
    self.tiBtn.nim_height = self.tiLine.nim_height;
    
    if (self.model.shouAddress.liaison.length) {
        self.desc2Lab.frame = CGRectZero;
        
        self.shouNameLab.text = [NSString stringWithFormat:@"%@ %@",self.model.shouAddress.liaison,self.model.shouAddress.tel];
        [self.shouNameLab sizeToFit];
        self.shouNameLab.nim_left = 59;
        self.shouNameLab.nim_top = 10 + self.marginLine.nim_bottom;
        self.shouNameLab.nim_width = self.bgView.nim_width - 70 - 10 - self.shouNameLab.nim_left;
        
        self.shouAddressLab.nim_width = self.shouNameLab.nim_width;
        self.shouAddressLab.text = self.model.shouAddress.address;
        self.shouAddressLab.nim_left = self.shouNameLab.nim_left;
        self.shouAddressLab.nim_top = self.shouNameLab.nim_bottom + 10;
        [self.shouAddressLab sizeToFit];
        self.shouAddressLab.nim_width = self.shouNameLab.nim_width;
        
        self.shouCompanyLab.nim_width = self.shouAddressLab.nim_width;
        self.shouCompanyLab.text = self.model.shouAddress.name;
        self.shouCompanyLab.nim_left = self.shouAddressLab.nim_left;
        self.shouCompanyLab.nim_top = self.shouAddressLab.nim_bottom + 5;
        [self.shouCompanyLab sizeToFit];
        self.shouCompanyLab.nim_width = self.shouAddressLab.nim_width;
        
        self.marginLine2.nim_left = 0;
        self.marginLine2.nim_top = self.shouCompanyLab.nim_bottom + 15;
        self.marginLine2.nim_width = self.bgView.nim_width;
        self.marginLine2.nim_height = 2;
    }else {
        self.desc2Lab.frame = CGRectMake(59, 34+self.marginLine.nim_bottom, self.bgView.nim_width - 70 - 10 - 59, 15);
        self.desc2Lab.text = @"收货信息";
        self.shouNameLab.frame = CGRectZero;
        self.shouAddressLab.frame = CGRectZero;
        self.shouCompanyLab.frame = CGRectZero;
        
        self.marginLine2.nim_left = 0;
        self.marginLine2.nim_top = self.desc2Lab.nim_bottom + 38;
        self.marginLine2.nim_width = self.bgView.nim_width;
        self.marginLine2.nim_height = 2;
    }
    
    self.shouImgView.nim_width = 22;
    self.shouImgView.nim_height = 22;
    self.shouImgView.nim_left = 20;
    self.shouImgView.nim_top = self.marginLine2.nim_top - (self.marginLine2.nim_top - self.marginLine.nim_bottom - self.shouImgView.nim_height) * 0.5 - self.shouImgView.nim_height;
    
    self.shouLine.nim_width = 1;
    self.shouLine.nim_height = 40;
    self.shouLine.nim_left = self.bgView.nim_width - 70 - self.shouLine.nim_width;
    self.shouLine.nim_centerY = self.shouImgView.nim_centerY;
    
    self.shouAddressImgView.nim_width = 18;
    self.shouAddressImgView.nim_height = 18;
    self.shouAddressImgView.nim_top = self.shouLine.nim_top + 2;
    self.shouAddressImgView.nim_left = self.shouLine.nim_right + (70 - self.shouAddressImgView.nim_width) * 0.5;
    
    self.shouDescLab.text = @"收货地址";
    [self.shouDescLab sizeToFit];
    self.shouDescLab.nim_top = self.shouAddressImgView.nim_bottom + 6;
    self.shouDescLab.nim_centerX = self.shouAddressImgView.nim_centerX;
    
    self.shouBtn.nim_left = self.shouLine.nim_right;
    self.shouBtn.nim_top = self.shouLine.nim_top;
    self.shouBtn.nim_width = 70;
    self.shouBtn.nim_height = self.shouLine.nim_height;
    
    self.linkLine.nim_width = 2;
    self.linkLine.nim_top = self.tiImgView.nim_bottom + 3;
    self.linkLine.nim_height = self.shouImgView.nim_top - 3 - self.linkLine.nim_top;
    self.linkLine.nim_centerX = self.tiImgView.nim_centerX;
    
    self.timeXingLab.text = @"*";
    [self.timeXingLab sizeToFit];
    self.timeXingLab.nim_left = 10;
    self.timeXingLab.nim_top = self.marginLine2.nim_bottom + 20;
    
    self.timetitleLab.text = @"提货时间";
    [self.timetitleLab sizeToFit];
    self.timetitleLab.nim_left = self.timeXingLab.nim_right + 3;
    self.timetitleLab.nim_top = self.timeXingLab.nim_top;
    
    self.timeLine.text = @"----";
    [self.timeLine sizeToFit];
    self.timeLine.nim_top = self.timetitleLab.nim_bottom + 20;
    self.timeLine.nim_centerX = self.bgView.nim_width * 0.5;
    
    self.beginBtn.nim_left = self.timeXingLab.nim_left;
    self.beginBtn.nim_width = self.timeLine.nim_left - 10 - self.beginBtn.nim_left;
    self.beginBtn.nim_height = 40;
    self.beginBtn.nim_centerY = self.timeLine.nim_centerY;
    
    self.beginField.frame = self.beginBtn.frame;
    if (self.model.beginTime.length) {
        self.beginField.text = self.model.beginTime;
    }
    
    self.endBtn.nim_left = self.timeLine.nim_right + 10;
    self.endBtn.nim_width = self.beginBtn.nim_width;
    self.endBtn.nim_height = 40;
    self.endBtn.nim_centerY = self.timeLine.nim_centerY;
    
    self.endField.frame = self.endBtn.frame;
    if (self.model.endTime.length) {
        self.endField.text = self.model.endTime;
    }
    
    self.marginLine3.nim_left = self.timeXingLab.nim_left;
    self.marginLine3.nim_top = self.endBtn.nim_bottom + 3;
    self.marginLine3.nim_width = self.bgView.nim_width - 2 * self.marginLine3.nim_left;
    self.marginLine3.nim_height = 1;
    
    self.dateField.frame = CGRectMake(10, self.marginLine3.nim_bottom + 10, self.bgView.nim_width - 20, 40);
    if (self.model.requireDate.length) {
        self.dateField.text = self.model.requireDate;
    }
    self.dateBtn.frame = self.dateField.frame;
    UIView *dateLeftView = [[UIView alloc] initWithFrame:CGRectMake(0, 12.5, 100, 15)];
    UILabel *dateXingLab = [UILabel new];
    dateXingLab.text = @"*";
    dateXingLab.font = [UIFont systemFontOfSize:14];
    dateXingLab.textColor = HexColor(0xF35959);
    [dateXingLab sizeToFit];
    dateXingLab.nim_left = 0;
    dateXingLab.nim_top = 0;
    [dateLeftView addSubview:dateXingLab];
    
    UILabel *dateTitleLab = [[UILabel alloc] initWithFrame:CGRectMake(dateXingLab.nim_right + 3, 0, dateLeftView.nim_width - dateXingLab.nim_right - 3, dateLeftView.nim_height)];
    dateTitleLab.text = @"要求到达时间";
    dateTitleLab.textColor = HexColor(0x2B2C44);
    dateTitleLab.font = [UIFont systemFontOfSize:14];
    [dateLeftView addSubview:dateTitleLab];
    
    self.dateField.leftView = dateLeftView;
    self.dateField.leftViewMode = UITextFieldViewModeAlways;
    
    self.marginLine4.nim_left = self.timeXingLab.nim_left;
    self.marginLine4.nim_top = self.dateField.nim_bottom + 10;
    self.marginLine4.nim_width = self.bgView.nim_width - 2 * self.marginLine4.nim_left;
    self.marginLine4.nim_height = 1;
    
    self.linkOrderField.frame = CGRectMake(10, self.marginLine4.nim_bottom + 10, self.bgView.nim_width - 20, 40);
    if (![FactoryMethod isNull:self.model.aorder]) {
        self.linkOrderField.text = self.model.aorder;
    }
    
    UILabel *linkOrderTitleLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 60, self.linkOrderField.nim_height)];
    linkOrderTitleLab.text = @"关联订单";
    linkOrderTitleLab.textColor = HexColor(0x2B2C44);
    linkOrderTitleLab.font = [UIFont systemFontOfSize:14];
    
    self.linkOrderField.leftView = linkOrderTitleLab;
    self.linkOrderField.leftViewMode = UITextFieldViewModeAlways;
    
    self.marginLine5.nim_left = self.timeXingLab.nim_left;
    self.marginLine5.nim_top = self.linkOrderField.nim_bottom + 10;
    self.marginLine5.nim_width = self.bgView.nim_width - 2 * self.marginLine5.nim_left;
    self.marginLine5.nim_height = 1;
    
    self.originalOrderField.frame = CGRectMake(10, self.marginLine5.nim_bottom + 10, self.bgView.nim_width - 20, 40);
    if (![FactoryMethod isNull:self.model.ynum]) {
        self.originalOrderField.text = self.model.ynum;
    }
    
    UILabel *originalOrderTitleLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 60, self.originalOrderField.nim_height)];
    originalOrderTitleLab.text = @"原始单号";
    originalOrderTitleLab.textColor = HexColor(0x2B2C44);
    originalOrderTitleLab.font = [UIFont systemFontOfSize:14];
    
    self.originalOrderField.leftView = originalOrderTitleLab;
    self.originalOrderField.leftViewMode = UITextFieldViewModeAlways;
    
    self.bgView.nim_height = self.originalOrderField.nim_bottom + 10;
    self.height = self.bgView.nim_bottom;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
